import Cookies from 'js-cookie';
import { onMounted } from 'vue'

export const getToken = () => {
  return Cookies.get('token') || '';
}

export const setToken = (token) => {
// 设置 token 到 cookie
  Cookies.set('token', token);
}

export const removeToken = (token) => {
// 设置 token 到 cookie
  Cookies.remove('token');
}

export const getUserId = () => {
  return Cookies.get('userid') || '';
}

export const setUserId = (userid) => {
// 设置 token 到 cookie
  Cookies.set('userid', userid);
}

export const removeUserId = () => {
// 设置 token 到 cookie
  Cookies.remove('userid');
}
export const setUserInfo = (UserInfo) => {
// 设置 token 到 cookie
  Cookies.set('UserInfo',UserInfo);
}

export const GetUserInfo = () => {
  return Cookies.get('UserInfo') || '';
}

// setUserId('e9ca23d68d884d4ebb19d07889727dae') 
// setToken('eyJhbGciOiJIUzI1NiIsInuR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiZXhwIjoxNzQ4MTIwNzU0fQ.Mu4tKjrQGG8gwDwfcLBXdF_Se8m7wOUTzSeU127VDxQ')

export const setUserPermission = (val) => {
// 设置 权限 到 cookie
console.log(val)
  Cookies.set('userPermission', JSON.stringify(val));
}
export const getUserPermission = () => {
  if(!Cookies.get('userPermission')) {
    return {}
  }
// 设置 权限 到 cookie
  return JSON.parse(Cookies.get('userPermission'));
}